/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 1e7, MOD = 998244353;

int a[maxn + 1], b[maxn + 1][6];

int add(int x, int y, int mod = MOD) { return ((x + y) % mod + mod) % mod; }

int mul(int x, int y, int mod = MOD) { return 1ll * x * y % mod; }

int main() {
  int n, x, y, m, k;
  cin >> n >> a[1] >> x >> y >> m >> k;
  for (int i = 2; i <= n; ++i) a[i] = add(mul(a[i - 1], x, m), y, m);
  b[1][0] = a[1];
  for (int i = 2; i <= n; ++i) {
    b[i][0] = add(a[i], b[i - 1][0]);
  }
  for (int i = 1; i <= n; ++i) {
    b[i][1] = add(add(b[i - 1][1], b[i - 1][0]), a[i]);
  }
  for (int i = 2; i <= k; ++i) {
    for (int j = i; j <= n; ++j) {
      b[j][i] = add(b[j - 1][i], b[j - 1][i - 1]);
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) ans ^= (1ll * b[i][k] * i);
  cout << ans << endl;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("E. Combinatorics Problem.in", "r", stdin);
  freopen("E. Combinatorics Problem.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
